﻿using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using System.Net;

namespace ASmile.Web
{
    /// <summary>
    /// host操作类
    /// </summary>
    public class HostHelper
    {
        public static IWebHostBuilder CreateWebHostBuilder(string[] args)
        {
            return
            WebHost
                .CreateDefaultBuilder(args)
                .ConfigureKestrel((context, options) =>
                {
                    if (Config.THIS.HttpPort > 0)
                    {
                        options.Listen(IPAddress.Any, Config.THIS.HttpPort);
                    }
                    if (Config.THIS.HttpsPort > 0)
                    {
                        options.Listen(
                            IPAddress.Any,
                            Config.THIS.HttpsPort,
                            listenOptions =>
                            {
                                listenOptions.UseHttps(Config.THIS.SSLFileName, Config.THIS.SSLFilePassword);
                            });
                    }
                });
                //.UseStartup<Startup>();
        }
    }
}